package com.meal.entity.base;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @program: meal->BaseEntity
 * @description: 实体类公共类
 * @author: yangzhanghui
 * @create: 2019-12-05 11:09
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder(toBuilder = true)
@Accessors(chain = true)
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity<T extends Model<T>> extends Model<T> {

    @CreatedBy
    @TableField("create_user")
    @ApiModelProperty(value = "创建人")
    private Integer createUser;

    @LastModifiedBy
    @TableField("update_user")
    @ApiModelProperty(value = "修改人")
    private Integer updateUser;

    @CreatedDate
    @TableField("create_time")
    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createTime;

    @LastModifiedDate
    @TableField("update_time")
    @ApiModelProperty(value = "修改时间")
    private LocalDateTime updateTime;

    @TableLogic
    @TableField("del_flag")
    @ApiModelProperty(value = "删除标识")
    private Integer delFlag;

    @Version
    @TableField("version")
    @ApiModelProperty(value = "版本号")
    private Integer version;

    @Override
    protected Serializable pkVal() {
        return null;
    }
}
